<?php

require_once 'common/conn.php';

$usercode = $_GET['usercode'];
if (!isset($usercode)) {
    $usercode = $_POST['usercode'];
}

$packid = $_GET['packid'];
if (!isset($packid)) {
    $packid = $_POST['packid'];
}

$db = new DBC();
$sql = "SELECT packid,productid,flashcode,type1 AS type,type3,name,url,imageURL FROM t_product WHERE packid = " . $packid . " AND status = 1 ORDER BY flashcode";
$data = $db->fetchData($sql);
//$sql = "UPDATE t_product SET downloadtimes = downloadtimes +1 WHERE packid = " . $packid;
//$db->execute($sql);
$sql = "SELECT productid FROM t_product WHERE packid = " . $packid . " AND status = 1";
$pids = $db->fetchData($sql);
if (count($pids) > 0) {
    foreach ($pids as $p) {
        $sql = "INSERT INTO t_device_product(usercode,productid,createTime) VALUES('" . $usercode . "'," . $p['productid'] . ",now())";
        $db->execute($sql);
    }
}
$result = array();
$result['products'] = $data;
echo json_encode($result);
?>
